package com.clickpaas.materialsprocurement.service.Impl;

import com.bizcloud.ipaas.t0ba0ba6afb694026b6b4e4e048af2b43.d20210202135416.model.PMSpurchaseApplyLineDTOResponse;
import com.clickpaas.materialsprocurement.dao.ReqLineDao;
import com.clickpaas.materialsprocurement.entity.ReqLineEntity;
import com.clickpaas.materialsprocurement.service.ReLineService;
import com.clickpaas.materialsprocurement.utils.DataInfoUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
@Slf4j
public class ReLineServiceImpl implements ReLineService {
    @Resource
    private ReqLineDao reqLineDao;
    /**
     * 获取请购单物料数据
     *
     * @param reqLineEntity
     * @return
     */
    @Override
    public List<PMSpurchaseApplyLineDTOResponse> getReLineInfo(ReqLineEntity reqLineEntity) {

        List<PMSpurchaseApplyLineDTOResponse> reqLineList;
        try {
            /**
             * 入参为空,不查询
             */
            if (null == reqLineEntity || DataInfoUtil.isAllFieldNull(reqLineEntity)){
                return null;
            }else {
                reqLineList = reqLineDao.getReLineByCondtion(reqLineEntity);
            }
        } catch (Exception e) {
            log.info("入参对象异常,请检查：【{}】,报错信息：【{}】",reqLineEntity,e);
            return null;
        }
        if (null != reqLineList && reqLineList.size()>0){
            return reqLineList;
        }
        return null;
    }

    @Override
    public List<ReqLineEntity> ApplyLineDataConver(List<PMSpurchaseApplyLineDTOResponse> applyLineList){
        return DataInfoUtil.castListCopy(applyLineList,PMSpurchaseApplyLineDTOResponse.class,ReqLineEntity.class);
    }
}
